import java.util.Timer;
import java.util.TimerTask;

public class TimerDemo {
    public static void main(String[] args) {
        Timer timer=new Timer();
        timer.schedule(new TimerTask(){     //有两个参数,第一个重写run方法,第二个是要设置的时间
            @Override
            public void run() {
                System.out.println("hello timer3");
            }
        },3000);    //在3秒中后,打印"hello timer"

        timer.schedule(new TimerTask(){
            @Override
            public void run() {
                System.out.println("hello timer2");
            }
        },2000);

        timer.schedule(new TimerTask(){
            @Override
            public void run() {
                System.out.println("hello timer1");
            }
        },1000);
        System.out.println("程序开始运行");
    }
}
